package lab02.test06;

public class Triangle {
    double side1;
    double side2;
    double side3;
    double area;
    double perimeter;   //定义三角形的三边，面积，周长。

    public void setSide1(double side1) {
        this.side1 = side1;
    }

    public void setSide2(double side2)
    {
        this.side2 = side2;
    }

    public void setSide3(double side3) {
        this.side3 = side3;
    }

    public double getSide1() {
        return side1;
    }

    public double getSide2() {
        return side2;
    }

    public double getSide3() {
        return side3;
    }

    public double getArea() {          //根据三边计算三角形面积
        double p = (side1 + side2 + side3) / 2;         //p代表海伦公式中的变量
        area = Math.sqrt(p * (p - side1) * (p - side2) * (p - side3));
        return area;
    }

    public double getPerimeter() {           //计算三角形周长
        perimeter = side1 + side2 + side3;
        return perimeter;
    }

    /*public void changeSide(double side1, double side2, double side3) {     //当三边不能构成三角形的时候，重新设置三边。
        this.side1 = side1;
        this.side2 = side2;
        this.side3= side3;
    }*/

    public void setNewSide1(double side1) {
        this.side1 = side1;
    }

    public void setNewSide2(double side2) {
        this.side2 = side2;
    }

    public void setNewSide3(double side3) {     //以上三个方法是当三边不能构成三角形时，重新得到三条边
        this.side3 = side3;
    }

    public double getNewSide1() {
        return side1;
    }

    public double getNewSide2() {
        return side2;
    }

    public double getNewSide3() {       //得到新的三条边
        return  side3;
    }

    public boolean judgeSide() {            //判断三条边能不能构成三角形
        if(side1 + side2 > side3 && side3 + side2 > side1 && side1 + side3 > side2 &side1 - side2 < side3 && side3 - side2 < side1 && side1 - side3 < side2) {
            return true;
        }
        else {
            return false;
        }
    }
}
